package org.codesketch.flamingo

import grails.converters.JSON

import org.codesketch.flamingo.domain.Response;

class AuthenticationController {

	AuthenticationService authenticationService
	
	static allowedMethods = [authenticate:'POST']
	
    def index() { }
	
	def authenticate() {
		Response<String> resp = new Response<String>();
		if(authenticationService.valid(params.username, params.password)) {
			resp.setStatus(200)
			resp.setMessage("OK")
			resp.setData(params.username)
		} else {
			resp.setStatus(401)
			resp.setMessage("Unauthorized")
			resp.setData(null)
		}
		render resp as JSON
	}
}
